'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:PersonnelYcsqCtrl
 * @description
 * # PersonnelYcsqCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('PersonnelYcsqCtrl', function($scope, $rootScope, DataService, openApi, Util, $routeParams, FormSubmit) {
        $scope.sheetObj = {};
        // 底部关联模块类型选框添加
        var carObj = {};
        carObj.sheettitle = "车牌号码";
        carObj.callback = function(item) {
            $scope.param.carInfo = item.selectTab
            $scope.param.carInfoContent = item.selectTabContent
        }
        $scope.sheetObj.carObj = carObj;
        $scope.showCarInfo = function() {
            var param = {}
            param.type = "车牌号码";
            DataService.getData(openApi.getKeyType, param).then(function(data) {
                console.log(data)
                $scope.sheetObj.carObj.tabList = data
                $scope.showSheet("carObj")
            })

        };
        $scope.showSheet = function(type) {
            var sheetObj = $scope.sheetObj[type]
            $scope.sheetObj.type = type
            $scope.sheetObj.tabList = sheetObj.tabList
            $scope.sheetObj.sheettitle = sheetObj.sheettitle
            $scope.sheetObj.ifshowSheet = true
            $rootScope.showMasker = true
        };

        $scope.submit = function() {
            // 底部类型end
            if (!$scope.param.startUseDate) {
                Util.Toast("请选择用车起始日期");
                return;
            }
            if (!$scope.param.endUseDate) {
                Util.Toast("请选择用车结束日期");
                return;
            }
            if (!Util.checkDays($scope.param.costTime)) {
                Util.Toast("用车时长要为0.5的倍数");
                return;
            }
            if (!$scope.param.carInfo) {
                Util.Toast("请选择车牌号码");
                return;
            }

            if (!$scope.param.remark) {
                Util.Toast("请填写用车事由");
                return;
            }

            // 提交
            var urlParam = "?operationId=-2" + "&&processId=" + $routeParams.id + "&&url=" + openApi.useCar
            var options = {};
            options.urlParam = urlParam;
            options.param = $scope.param
            var TVtype;
            TVtype = Util.getTVType(); //根据页面的来源来判断是发起的流程还是修改的流程，如果是发起的则不管，如果是修改的则获取数据用来回显
            // 如果是修改页面的话则提交的地址不一样，参数一样
            if (TVtype == Util.UPDATE) {
                options.url = openApi.ip + openApi.useCar
            }
            new FormSubmit(options);
        };
        var init = function() {
            // 获取回显的详细信息
            Util.getDetailData($routeParams.id, function(data) {
                $scope.param = data;
            });
            // 显示审批记录判断
            Util.showloglist($routeParams.id, function(data) {
                $scope.logData = data;
            });

        };
        // 初始化
        init();
    });
